package org.douxiaoban.client.api;

import org.douxiaoban.client.R;
import org.douxiaoban.client.adapter.MailAdapter;



import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.*;

public class DoubanList {

	protected View mMainView;
	protected View mProgressBar;
	protected ListView mListView;
	protected BaseAdapter mAdapter;
	protected DoubanListType mType;
	
	protected int mCount;
	protected int mFirstId;
	protected int mLastId;
	
	
	protected boolean mIsEnd;
	protected boolean mIsFirst;
	protected boolean mIsUpdateing;
//	//获取更多的时候的补偿,当去获取更多时有更新(等新的api把!)
//	private int mCompensateCount;
	private Context mContext;
	private View mFootView;

	public DoubanList(Context context,BaseAdapter adapter, DoubanListType type){
		
		mContext = context;
		LayoutInflater flater = LayoutInflater.from(context);
		mMainView = flater.inflate(R.layout.list, null);
		init(adapter, type);		
		reset();
		//mListView.setAdapter(mAdapter);
	}
	
	//miniblog
	public DoubanList(Context context, BaseAdapter adapter, DoubanListType type, View mainView){
		mContext = context;
		mMainView = mainView;
		init(adapter, type);
		reset();
	}
	
	private void init(BaseAdapter adapter, DoubanListType type){
		LayoutInflater flater = LayoutInflater.from(mContext);
		mListView = (ListView)mMainView.findViewById(R.id.listView);
		mProgressBar = mMainView.findViewById(R.id.listProgressBar);
		
		mAdapter = adapter;
		mFootView = flater.inflate(R.layout.foot, null);
		mListView.addFooterView(mFootView);
		
//		LinearLayout container =(LinearLayout)mMainView.findViewById(R.id.AdLinearLayout);
//		container.addView(new AdGroupLayout((Activity)mContext));
		
		mType = type;
		
	}
	
	public void reset(){
		mCount = 0;		
		mFirstId = -1;
		mLastId = -1;	
		
		mIsEnd = false;
		mIsFirst = true;
		mIsUpdateing = false;
	}
	
	public void updateFootView(){
		ProgressBar pgb = (ProgressBar)mFootView.findViewById(R.id.footProgressBar);
		pgb.setVisibility(View.GONE);
		TextView textView = (TextView)mFootView.findViewById(R.id.footTextView);
		textView.setText("End");
	}
	public View getMainview(){
		return mMainView;
	}
	public void setMainView(View v){
		mMainView = v;
	}
	
	public View getProgressBar(){
		return mProgressBar;
	}	
	public void setProgressBar(View v){
		mProgressBar = v;
	}
	
	public ListView getListView(){
		return mListView;
	}
	public void setListView(ListView v){
		mListView = v;
	}
	
	public BaseAdapter getAdapter(){
		return mAdapter;
	}
	public void setAdapter(BaseAdapter adapter){
		mAdapter = adapter;
	}
	
	public DoubanListType getType(){
		return mType;
	}
	public void setType(DoubanListType type){
		mType = type;
	}
	
	public int getCount(){
		return mCount;
	}
	public void setCount(int count){
		mCount = count;
	}
	
	public int getFirstId(){
		return mFirstId;
	}
	public void setFirstId(int id){
		mFirstId = id;
	}
	
	public int getLastId(){
		return mLastId;
	}
	public void setLastId(int id){
		mLastId = id;
	}
	
	public boolean getIsFirst(){
		return mIsFirst;
	}
	public void setIsFirst(boolean b){
		mIsFirst = b;
	}
	
	public boolean getIsUpdateing(){
		return mIsUpdateing;
	}
	public void setIsUpdateing(boolean b){
		mIsUpdateing = b;
	}
	
	public boolean getIsEnd(){
		return mIsEnd;
	}
	public void setIsEnd(boolean b){
		mIsEnd = b; 
	    if(b){
	    	mFootView.findViewById(R.id.footProgressBar).setVisibility(View.GONE);
	    	((TextView)mFootView.findViewById(R.id.footTextView)).setText("木有数据了！");
	    }
	}

}